package com.feather.tenia;

import java.sql.SQLException;
import java.util.List;
import java.util.Map;

import com.feather.common.data.DataTable;
import com.feather.common.db.Connector;
import com.feather.common.db.TypeMapping;

/**
 * @author flogyin
 */
public interface Tenia {
	String getCaption();

	void setCaption(String caption);

	String getCatalog();

	String getSchema();

	Connector getConnector();

	JdbcProperty getJdbcProperty();

	boolean isCacheProcedureColumn();

	void setCacheProcedureColumn(boolean cache);

	boolean isCheckFetcher();

	void setCheckFetcher(boolean check);

	boolean isCheckSaver();

	void setCheckSaver(boolean check);

	TypeMapping getTypeMapping();

	Map<String, Procedure> getProcedureCache();

	boolean hasSqlTypeMap(String dataTypeName);

	int getSqlType(String dataTypeName);

	void mapSqlType(String dataTypeName, int dataType);

	void clearSqlTypeMap();

	List<ProcedureMeta> listProcedure() throws SQLException;

	List<ProcedureMeta> listProcedure(String catalog, String schema, String name) throws SQLException;

	// List<String> listCommand() throws SQLException;

	// Command getCommand(String commandName) throws SQLException;
	Procedure getProcedure(String procedureName) throws SQLException;

	Procedure getProcedure(String catalog, String schema, String name) throws SQLException;

	// Procedure getProcedure(Meta meta) throws SQLException;

	/**
	 * 为了效率, sql语句及 placeholder写法正确性不做检测分析. 参数为 Array or List 时: 长度必须匹配 sql 中占位符
	 * ? 的个数, 且不解析（不支持） placeholder 语法. 参数为 Map 时: 必须使用 placeholder 语法来绑定, 且不再处理
	 * sql 中占位符 ?.
	 * 
	 * eg: [Array or List] INSERT INTO t_type_list( a, b, c, d, e ) VALUES ( ?,
	 * ?, ?, ?, ? ) [Map] INSERT INTO t_type_list( a, b, c, d, e ) VALUES (
	 * #{a}, '${b}', str_to_date('${c}','%Y-%m-%d'), '${d,jdbcType=VARCHAR}',
	 * #{e,jdbcType=BIT} ) [Map] INSERT INTO t_type_list( a, b, c, @<d>{,d}@
	 * 
	 * @<e>{,e @ ) VALUES ( #{a}, '${b}', ${c} @<d>{,#{d}}@ @<e>{,'${e}'}@ )
	 */
	boolean execute(String sql) throws SQLException;

	boolean execute(String sql, Object[] parameters) throws SQLException;

	boolean execute(String sql, List<Object> parameters) throws SQLException;

	boolean execute(String sql, Map<String, Object> parameters) throws SQLException;

	DataTable executeQuery(String sql) throws SQLException;

	DataTable executeQuery(String sql, Object[] parameters) throws SQLException;

	DataTable executeQuery(String sql, List<Object> parameters) throws SQLException;

	DataTable executeQuery(String sql, Map<String, Object> parameters) throws SQLException;

	MetaDataColumnHandler getMetaDataColumnHandler();

	void setMetaDataColumnHandler(MetaDataColumnHandler handler);

	ExecuteCallback getExecuteCallback();

	void setExecuteCallback(ExecuteCallback callback);

	void setExecuteCallback(ExecuteCallback callback, boolean overall);

	TeniaHelper getHelper();

	void setHelper(TeniaHelper helper);

	boolean getPlaceholderEmptyEqualsNull();

	void setPlaceholderEmptyEqualsNull(boolean equals);
}
